home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack99 / admin-howto.txt < prev    next >
Encoding:
Text File  |  1999-04-11  |  23.6 KB  |  462 lines

  1. Release Date : 6th April 1999
  2. Previous Versions: none
  3.  
  4. Linux Mini Administration HOWTO.
  5. By Kostas Petrakis aka Pestilence.
  6.  
  7. This was written mostly as a small guide to some NT based co-workers here at
  8. my work so that they could check a few stuff on Linux systems if needed.
  9. Also i decided to write this because there are lots of administration howto's
  10. out there which are also kinda old.
  11. This paper in not a super-detailed paper, for this purpose there are other
  12. papers mentioned in the end of this HOWTO. This paper was intented to give a
  13. small clue of what people should check before they decide to allow services to
  14. run on their systems, or fully connect to the Internet.
  15.  
  16. More and more people everyday connect their systems to the Internet, and more
  17. people are seriously thinking of buying either a leased line, or a cable modem
  18. and stay 24-7 on-line.
  19. There are allot of systems on-line some of them are tight secured, and
  20. others are openwide yelling to be hacked.
  21. This text is intented to give a small idea of what someoone should check at
  22. his system before he goes on-line, or what to secure once he is on-line.
  23.  
  24. SERVICES
  25.  
  26. Many servers over the Internet offer a wide of services to their users and
  27. customers, what comes here is a big risk since time has prooved that allot
  28. of services are usually buggy and easily exploitable providing root access, or
  29. other kinds of access to remote or local users.
  30. An administrator of either a  home system, or a company, should be
  31. able to keep on track of this bugs and try to keep his software as more up to
  32. date as he can. This can be done by subscribing to several security mailing
  33. lists, such as Bugtraq, or Cert (Links included in the end of this document).
  34. Another major issue on services are the configurations of each service.
  35. Services usually follow a "guideline" of operation, which is usually declared
  36. in the configuration section of each service. Most buggy services have
  37. prooved to be: sendmail, web servers, ftp servers, and generally all
  38. services that have to do with interaction between the user and the file
  39. system. People oftenly like to bypass the configuration of services, and like
  40. to leave them the way they where installed, without even taking a look at what
  41. configurations are offering, this is a major mistake oftenly found to Junior
  42. administrators, or newcomers to the Unix world. 
  43.  
  44. WEB SERVERS
  45.  
  46. Web servers keep their configuration files under the directory /etc/httpd/conf
  47. (default installation from the Linux distribution, which we encourage you to
  48. update to the most recent), or to /usr/local/apache/conf if recompiled, and you
  49. leave the paths intact.
  50. Take a good look at the configuration, sometimes you will see it has entrys
  51. you wouldn't want to, the one you should surely check is under what user does
  52. httpd operate, make sure httpd runs under user:nobody and group:nobody. Check
  53. that the log directory is not user writable, you dont want users "playing" with
  54. your log files now do you?.
  55. The biggest security thread though lately with httpd, is it's CGI's.
  56. CGI's are small programs written either in perl, or C, which are used by the
  57. webserver, and are usually the most dangerous.
  58. CGI's if coming from some unknown or not that reliable source should be
  59. checked for possible problems in their code which would risk the security of
  60. your webserver. The security risks a CGI could possibly create are the
  61. following:
  62. 1) Expose Information of your Webserver and its local filesystem/ users.
  63. 2) Search Scripts are the most dangerous, since a small missconfiguration,
  64. would allow remote users to search your entire filesystem, and reveal high
  65. risk information to them. Even if you dont run your webserver as root, you
  66. still have chances to run in big trouble.
  67. Try not to give access to users (if you allow user webpages, or have
  68. virtualhosts) to their cgi-bin directories, instead let them mail you and ask
  69. you to check a cgi script they want to use, or even better give them a list of
  70. CGI's they can use, that you trust.
  71. Avoid suid privilleged scripts, they are high risk and there is rarely the
  72. need for a script to be under such privilleges.
  73. Try to have scripts that validate the contect submmited by forms, validation
  74. of data is a more secure way to control what is being passed to your system.
  75. Avoid scripts that will allow remote systems to use them (Matt's scripts allow
  76. this feature).
  77. And finally avoid all scripts that have to do with web interfaces on
  78. services...this scripts usually are of super high risk!
  79. More on web security can be found following the links below.
  80.  
  81. FTP
  82.  
  83. FTP servers, are another high Risk on systems, generally it would be wise to
  84. avoid the use of FTP if there is no need, or if there is a need you should
  85. avoid having anonymous ftp enabled.
  86. FTP servers are used for file transfers between hosts. More oftenly they are
  87. used to give users of systems access to their websites.
  88. If you are from the persons that love, or like to contribute to the Linux
  89. community either with having a public ftp server offering mirroring services,
  90. or using the ftp server to release your software you should be very carefull,
  91. of what you give, and what you allow remote users to have.
  92. The default ftp daemon that comes with the Linux installation is wu-ftp, this
  93. server is simple, and good, but unfortunately several bugs where discovered,
  94. and it seems updates are not that often to it. So i recommend the use of a
  95. more advanced FTP server, which will allow you to have more detailed
  96. configuration files. One ftp server i like allot and use oftenly is ProFTPd,
  97. this server has an apache like configuration file, and allows the admin to
  98. have full control over it.
  99. Its widely used on major sites such as Linuxberg, Freshmeat, it updates
  100. frequently and they have a very good responce time over bugs found on it.
  101. It's site offers a very good documentation, and the configuration of it is
  102. really easy even from the average users who want to give partial access to
  103. remote users.
  104. It can run as a standalone daemon, or through inetd with the use also of
  105. tcp-wrappers.
  106. For instance lets have a look how ProFTPd is configured to allow remote users
  107. to upload to a directory, but deny them to download from that dir (good to
  108. deny warez usage of your ftp server) and also deny them the creation of
  109. subdirectories.
  110. <Anonymous /home/ftp>
  111.  
  112.               User ftp
  113.               Group ftp
  114.               UserAlias anonymous ftp
  115.  
  116.               <Directory *>
  117.  
  118.                      <Limit WRITE>
  119.                      DenyAll
  120.                      </Limit>
  121.  
  122.               </Directory>
  123.  
  124.               <Directory incoming>
  125.  
  126.                      <Limit STOR>
  127.                      AllowAll
  128.                      </Limit>
  129.                      <Limit READ>
  130.                      DenyAll
  131.                      </Limit>
  132.  
  133.               </Directory>
  134.  
  135.         </Anonymous>
  136. This is what the entry looks like in proftpd.conf, this denies the remote
  137. anonymous users to write to any directory except of incoming, in that
  138. directory anonymous users are allowed to upload files, but they are denyed of
  139. reading the directory, deletetion of files, or the creation of
  140. subdirectories. If you are more paranoid and even if you have limited the usage
  141. of ftp only to valid users but you need more security, you can make use of a
  142. nice firewall, this though requires that most of your ftp users are local
  143. users, and remote users that are allowed usage of the ftp server have static
  144. IP's. To do so, you would setup a firewall allowing access from your subnet,
  145. and the remote users and would DENY everyone else trying to connect to it.
  146.  
  147. SHADOW PASSWORDS
  148.  
  149. One of the most important things is the password management. Passwords are
  150. held in the /etc/passwd file (in case you didn't know...). Leaving password
  151. files like that is a high security risk, and even if you don't allow access to
  152. the system to any user, should be more secure.
  153. Password files can be more secure with the usage of shadow, since password
  154. files are user readable you should switch to shadow (i don't understand why
  155. some distributions of Linux don't install by default shadowing), anyway as we
  156. said /etc/passwd is world readable, this means that any user with access to
  157. your system is able to read the password file. The encryption of password
  158. files is really weak, and a simple user with a password cracker would be able
  159. to crack a few passwords in a few minutes. Its highly advisable to all users either with local
  160. boxes or company administrators to switch to shadowing.
  161. To use shadowing on your system you only have to run the pwconv command
  162. usually residing in the /usr/sbin directory. This will create a seperate file
  163. in the /etc dir called shadow, which holds the encrypted passwords, and will
  164. replace the password field in the /etc/passwd file with a "x" e.g
  165.  
  166. pestilence:x:500:500::/home/pestilence:/bin/bash
  167.  
  168. This is the entry in passwd after the usage of shadow.
  169. The original password is kept in /etc/shadow which is readble only by root,
  170. thus denying now the local users to "take a look" at your passwords.
  171. For more security, if you use a radius server with the companion of a cisco
  172. router for authentication, it would be wise to deny access to users at your
  173. system, to do this simply change the shell entrys in the passwd file to some
  174. non-existened shell.
  175.  
  176. POP
  177.  
  178. POP is used to allow users to retrieve their e-mail remotely. There aren't much
  179. of pop daemons, but its preffered not to use the default that comes with the
  180. installation (ipop3d), i would advise you to use one such as qpopper, which
  181. runs through inetd and can be used with TCP Wrappers.
  182. POP is a service that usually is wide open, this means that users that have
  183. accounts on your system, but use also on some other ISP can connect to your
  184. system and retrieve their mail.
  185. Usually it's left like that, but if you are really paranoid you can block all
  186. remote systems and allow only local users to connect and retrieve their mail.
  187. Just 1 thing must be sure, don't install a pop daemon that doesn't get the
  188. needed support by it's authors, or doesn't produce some kind of detailed logs
  189. (such as failed password entry attempts, or connections).
  190.  
  191. SENDMAIL
  192.  
  193. Here things get a bit more complicated, sendmail is the daemon used to send
  194. and receive e-mails between hosts.
  195. Sendmail uses several configuration files, with its main config file being
  196. sendmail.cf.
  197. Through this file you declare the files to be used for various purposes, such
  198. as the list with the allowed domains to use sendmail (ip-allow, name-allow),
  199. and the relay list, which contains the domains of virtualhosts you host.
  200. Lets take a closer look to sendmail.
  201. Unfortunately sendmail is propably one of the most buggy services on the
  202. Internet, up to now nearly all versions of it have either a remote, or local
  203. exploitation.
  204. Because of this problems you should be really carefull with sendmail, a small
  205. missconfiguration might cause you a big headache later.
  206. The main files you should be carefull with are:
  207. ip-allow --> here you enter all the IP's you want to allow to use your
  208. sendmail...don't leave it blank, otherwise you will have the whole Internet
  209. using your sendmail to mail.
  210. name-allow --> same as above but here you enter the hostnames of the systems
  211. (usually used when VirtualHosting is being done on your systems).
  212. relay --> This file contains the host to wich we allow relaying...this also
  213. shouldn't be left empty.
  214. sendmail.cw --> this file holds all the aliases for your system, this is again
  215. used if you host several virtual domains.
  216. Don't forget to oftenly upgrade your sendmail...yes i know this is kinda like
  217. a small pain in the ass, but it's also your only way to prevent the damage
  218. that a newly discovered bug can produce.
  219.  
  220. DNS
  221.  
  222. DNS is the service used to resolve the ip address of a host to a valid
  223. hostname.
  224. All big networks with their own domain use DNS, DNS has been subject to heavy
  225. remote exploitations in the past, and also is a service than can be used to
  226. give away allot of usefull info to intruders (such as your network systems,
  227. intruders combining the BIND version can sometimes guess the remote O/S and
  228. it's version). It's high advisable to move to BIND 4.9.7 or the 8.X series, if
  229. you are still running a 4.9.6 series of it, then you are vulnerable to a
  230. remote root exploitation.
  231. Make sure you have configured DNS properly, otherwise you might experience
  232. problems. Also the use of a firewall (for the interactivy between the primary
  233. and the secondary nameserver) would be highly recommended.
  234.  
  235. LOGGING
  236.  
  237. One of the most important aspects of system administration, is extensive
  238. logging, and also constant monitoring of the systems.
  239. Linux logs use various loggers, all of the logs are kept under /var/log.
  240. Let's take a better look at the loggers of Linux:
  241. messages --> here the system ouputs various kernel, and service messages with
  242. the use of sysklogd
  243. secure --> here the system logs connection attempts to various ports from
  244. local, or remote hosts.
  245. mailog --> The sendmail daemon logs nearly everything here.
  246. xferlog --> the ftp daemon outputs its messages here.
  247. wtmp --> When a user logs, or the system reboots this file changes, it's a
  248. binary file and you can't "cat" it or "tail" it, to get access to it you use
  249. the "last" command. This command outputs formated the data kept in wtmp.
  250. System logs allthough are kept under root privilleges doesn't mean once hacked
  251. they cant be modified, there are various tools in the trade which allow users
  252. to erase specific strings from them and thus hide their appearance on your
  253. systems. A way to make it more difficult to erase their presence from the logs
  254. (allthough this doesn't mean they cant still erase), is to use remote logs, 
  255. sysklogd has a feature, which allows system admins to log also on remote
  256. systems. I would reccomend this method, since it allows you to have a seperate
  257. log file on a remote system, and since the hacking scene has allot of newbies
  258. they nearly never check for remote logs.
  259. Allthough the logging facility of Unix systems is good, its not designed to
  260. heavy log. To have a better chances of detecting suspicious moves, i recommend
  261. log daemons for this specific task...detect and log, such loggers are iplog
  262. (which i widely use on my systems). Iplog is a set of 3 log daemons:
  263. tcplog --> logs and detects all tcp connections, it's also able to detect and
  264. log, scans using nmap.
  265. udplog --> logs all udp traffic
  266. icmplog --> logs all icmp traffic
  267. Always try to enable seperate logs for all your daemons (e.g qpopper -->
  268. /var/log/pop), this makes the monitoring process more easy.
  269. Get logcheck,this program will scan your regular logs for security
  270. violations, Unusuall system events, etc.
  271. Try to monitor regulary your systems logs...don't let them pass by, before the
  272. storm there are always some drops of rain...so you might be lucky and stop the
  273. intruders before they gain access. Make some shell script for your logs, and
  274. make them scan your logs for specified strings, enable their usage with the
  275. cron daemon, and make them check the logs in small period of time, so you can
  276. have a nice organized report in small time periods, without confusing your
  277. head in the (usually) huge system logs.
  278.  
  279. XWINDOWS
  280.  
  281. Xwindows is another security headache.
  282. Unfortunately Xwindows are allot of risk, so i would advise if you use a
  283. system as a server, not to use Xwindows, as you risk your security with their
  284. usage.
  285. If though you need to make use of them, make sure to setup some security, use
  286. some firewall, and don't forget of the "xhost -" command which will disable
  287. remote access to your X facility.
  288.  
  289. TELNET
  290.  
  291. If there isn't a real necesity of it, disable it. Allthough telnet by itself
  292. isn't that much of a security risk, it can be usefull to future intruders to
  293. work their way in e easily. If you need telnet, try to setup a firewall to
  294. restrict access to it.
  295. A simple move also to the total newbies would be to change you /etc/issue.net
  296. file, issue.net usually contains the type of O/S you run, and it's used as a
  297. banner to telnet connections. Allthough there are toold in the trade to detect
  298. what a remote systems O/S is (nmap, quesso), there are also plenty of windows
  299. hacker wannabes which usually will just telnet to check what O/S your
  300. running...deny (even if it's really easy to determine the remote O/S) them
  301. knowledge on your system.
  302.  
  303. KERNEL OPTIONS
  304.  
  305. On the 2.2.x series of kernels there are a few interesting options using
  306. booleans under your /proc/sys/net/ipv4 folder, this are icmp_echo_ignore_all,
  307. icmp_echo_ignore_broadcasts .etc, this files are used to specify some
  308. networking "reactions" of your system...it is advised (not necessary though)
  309. to:
  310. echo 1 > 
  311. those files, this will prevent ping replys to ping requests, and also will
  312. help you avoid smurf attacks over your network.
  313. tcp_syncookies is also advised to be echoed to 1, if your system is a widely
  314. used server.
  315. While compiling the 2.2.x kernel don't forget to include as many networking
  316. options as you can, such as routing messages, firewall support, etc.
  317. This will help you setup a more effectively working network.
  318.  
  319. SNIFFERS
  320.  
  321. Allthough sniffers aren't necessary to run all the time, it's wise to use them
  322. time to time.
  323. Network sniffers catch and display the datagrams moving around your network,
  324. it's usually a helpfull way to detect problems in your network.
  325. Latest kernels have also the abillity to detect if some device has entered
  326. promiscous mode (sniffer activated on some device). Make sure simple users dont
  327. have access to the sniffer, otherwise you will have big time troubles (since
  328. usually most services use plain text passwords).
  329. There is a big collection of good sniffers, so i wont discuss any of them...i
  330. usually fire up X and run Ethereal if there is a big need to do so.
  331.  
  332. AUDITING TOOLS
  333.  
  334. This tools are widely used by hackers to scan networks for known problems...so
  335. if hackers use them, you should also use them.
  336. Nessus is at the moment the best tool for such a task, its nearly
  337. updated everyday and currently it supports 209 security checks.
  338. Always run a scan on your network, check if you missed something, don't allow
  339. intruders gain advantage of something you forgot.
  340. This tools should be used very often on ALL your systems.
  341.  
  342. TEMPORARY SYSTEMS
  343.  
  344. Allot of times before i install a server, i temporary connect it to the
  345. network so i can ftp and fetch all the needed files.
  346. Since this systems are getting ready to either replace an existing server, or
  347. be a part of the network as new a server, you should be very carefull.
  348. Intruders dont always scan a single system, they might scan a whole subnet to
  349. get information on every system you have running on your network. So even if
  350. that system is a temporary one, don't bypass it's configuration, configure it
  351. to be as secure as it can be, and try to deny every kind of connection to it
  352. (use a firewall or something).
  353.  
  354. ## /etc/inetd.conf ##
  355.  
  356. Through this file some of the systems services are handled. The default file
  357. has many useless and unwanted services open. You should modify this file
  358. immediately after you install your system.
  359. Close nearly all ports, and leave open only those you need, echo, time, date
  360. and such ports are rarely used, and are not needed by any programs, so make
  361. sure you disable them.
  362. Services in inetd.conf have the abillity to work with tcp_wrappers. We are
  363. going to explain tcp_wrappers in the next section.
  364.  
  365. TCP WRAPPERS
  366.  
  367. Tcp Wrappers are files that are used to restrict access to your system(
  368. allthough i prefer using a firewall for this kind of work). If you are new to
  369. the firewall world, and need really quickly to restrict access to some
  370. services use them, but then go and read the firewall HOWTO :).
  371. The best way would be to use both a firewall and tcp wrappers.
  372. Tcp wrappers use the files: /etc/hosts.allow and /etc/hosts.deny, hosts.allow
  373. holds all the ip addresses of the systems or subnets you want to allow access
  374. to services, and hosts.deny include hosts that are denyed to access services.
  375. WARNING: Not all services use tcp wrappers, for instance sendmail is now a
  376. stand alone daemon, so tcp wrappers wont work with it, make sure you see if a
  377. service supports tcp wrappers before feeling "kinda" secure.
  378.  
  379. FIREWALLS
  380.  
  381. Firewalls are something that every administrator loves to have on his network,
  382. firewalling can have many different faces.
  383. 1) Connect a Internal Network through a single system (also called
  384. masquerading, but it also can act as a firewall, denying the remote users to
  385. log into the internal Network).
  386. 2) A system which through a program such as ipfwadm (for the 2.0.x kernels)
  387. and ipchains (for the 2.2.x kernels) can block and filter connections to user
  388. specified ports.
  389. A firewall acts as a wall between your system and the Internet, you configure
  390. it the way you like it, and it acts that way.
  391. For instance on my system (kernel 2.2.4) when i want to block users connecting
  392. to my telnet port, i would issue the following command:
  393. ipchains -A input -p tcp -s 0/0 -d 194.xxx.xx.xx telnet -j DENY -l
  394. Let's take a better look at this commmand:
  395. -A input --> ipchains after installation come with 3 preinstalled chains
  396. (input/output/forward, meaning the input data, output data, and finally
  397. forwarding data), with the -A flag we tell ipchains to Append our "rule" to
  398. the chain.
  399. -p tcp --> here we specify the protocol, i think the protocol i
  400. mention is obvious...other protocols include udp, and icmp
  401. -s 0/0 --> -s stands for source IP/host/subnet, you can either specify a whole
  402. subnet or a single IP, 0/0 stands for everyone...so we tell ipchains to match
  403. any ip address to this rule
  404. -d 194.xxx.xx.xx --> -d stands for destination IP/host/Network, here we
  405. specified a single IP (xxx used for privacy reasons, change them to your IP
  406. address)this ip is the IP of the destination host, meaning the host that
  407. receives all the data, usually you would specify your system, unless you have
  408. a router-box
  409. telnet --> after the destination host you specify the port, or
  410. service, ipchains can understand services which already exist in the
  411. /etc/service file, otherwise you need to specify a port / range of ports. For
  412. instance if we wanted to block ports from 6000 up to 6010 we would type:
  413. 6000:6010 
  414. -j DENY --> here we declare to ipchains what to do with
  415. datagrams that match this rules, simply here we DENY them, other methods
  416. include ACCEPT and REJECT
  417. -l --> -l stands for logging, enabling this options ipchains will output
  418. through the kernel into /var/log/messages every packet that matches this
  419. rules...be aware that this produces usually some heavy logs.
  420. Remember that when you create a rule think wisely, this service may be
  421. needed, or some other hosts must have access to it, by blocking a needed
  422. service you might create some problems.
  423. Always remember that when you want to block a service, but you want to give
  424. access to certain systems/networks, you have to declare first the ACCEPT
  425. rules, and then the DENY, otherwise all hosts will be denyed, since ipchains
  426. compares the datagrams with the chains in a descenting order.
  427. For example say we own pestilence.foo.com and we want to grant access to the
  428. ftp service to cool.foo.com, but DENY everyone else. We would type the
  429. following:
  430. ipchains -A input -p tcp -s cool.foo.com -d pestilence.foo.com ftp -j ACCEPT
  431. ipchains -A input -p tcp -s 0/0 -d pestilence.foo.com ftp -j DENY -l
  432.  
  433. Now cool.foo.com has access to out ftp, but the rest of the Internet doesn't.
  434. For more information on firewalling take a look at the HOWTO.
  435.  
  436. Comments, suggestion
  437. pestilence@netplan.gr
  438.  
  439. flames > /dev/null /* keep them to you :p */
  440.  
  441. Further References
  442. Here are links that every admin should visit...
  443.  
  444. http://www.genocide2600.com/~tattooman  /* The biggest Security archive of
  445. Planet earth...just name it...tattoo has it...*/
  446. http://howto.linuxberg.com /* All the known Linux HOWTO's */
  447. http://www.geek-girl.com/bugtraq/index.html /* All BUGTAQ postings are there*/
  448. http://www.technotronic.com /* Another security related site, worth looking */
  449. http://www.rewted.org /* Same as above */
  450. http://www.freshmeat.net /* Nearly every known Linux app indexed */
  451. http://www.linuxberg.com /* The Linux tucows site */
  452.  
  453. /* and finally some news produced in a way you never saw: (thats for the
  454. fun...)*/ 
  455. http://www.innerpulse.com 
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.